package com.tenglong.teacher.ui.adapter.viewholder;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.netease.nim.uikit.common.util.sys.TimeUtil;
import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.InfomMessageInfo;
import com.tenglong.teacher.data.resultInfo.MessageInfo;
import com.tenglong.teacher.ui.adapter.MessageAdapter;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;

/**
 * @author hdx on 2019/3/27.
 */
public class InformViewHolder extends BaseViewHolder<MessageInfo> {
    private TextView title, content, time;
    private MessageAdapter.MessageListener listener;
    private RecyclerView.Adapter mAdapter;

    public InformViewHolder(View itemView) {
        super(itemView);
        initView();
        setListener();
    }

    public InformViewHolder(View itemView, MessageAdapter.MessageListener listener, RecyclerView.Adapter adapter) {
        this(itemView);
        this.listener = listener;
        this.mAdapter = adapter;
    }

    private void setListener() {
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onInformListener(getLayoutPosition());
                }
            }
        });
    }

    private void initView() {
        title = itemView.findViewById(R.id.title);
        content = itemView.findViewById(R.id.content);
        time = itemView.findViewById(R.id.time);
    }

    @Override
    public void setLayoutInfo(MessageInfo info) {
        if (info instanceof InfomMessageInfo) {
            InfomMessageInfo data = (InfomMessageInfo) info;
            title.setText(data.title == null ? "" : data.title);
            content.setText(data.content == null ? "" : data.content);
            time.setText(TimeUtil.getDateString(data.updateDate));
        }
    }
}
